 <template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true">
      <el-form-item label="用户名" prop="username">
        <el-input
          v-model="queryParams.username"
          placeholder="请输入用户名"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
    <el-form-item label="用户状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择用户状态" clearable>
            <el-option
                v-for="item in this.questionTypelist"
                :key="item.key" 
                :value="item.key" 
                :label="item.value"
              ></el-option>
        </el-select>
    </el-form-item>

      <el-form-item>
        
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery" >搜索</el-button>
      </el-form-item>
    </el-form>
 

    <el-table v-loading="loading" :data="roleList">
     
       <el-table-column prop="id" label="序号" width="80px"/>
      <el-table-column prop="username" label="用户名"/>
      <el-table-column prop="realname" label="真实姓名"/>
      <el-table-column prop="sex" label="性别" width="60px;" :formatter="formatSex"/>
      <el-table-column prop="phone" label="手机号"/>
      <el-table-column prop="addTime" label="创建时间" width="160px" />
      <el-table-column prop="company" label="公司名称"/>
      <el-table-column prop="status" label="用户状态" :formatter="questionTypeFormatter" width="140px"/>
      <el-table-column width="160px" label="操作" align="center">
        <template slot-scope="{row}">
          
          <router-link :to="{path:'/user/all/detail', query:{id:row.id}}" class="link-left">
            <el-button size="mini" >编辑</el-button>
          </router-link>
          <!-- <el-button  size="mini" type="danger" @click="handleDelete(row)" class="link-left">删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParam.pageNum"
      :limit.sync="queryParam.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改角色配置对话框 -->

    <!-- 分配角色数据权限对话框 -->
 
  </div>
</template>

<script>
import { check,edit,getdetail,getpage} from "@/api/user";

export default {
  name: "Role",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 角色表格数据
      roleList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示弹出层（数据权限）
      openDataScope: false,
      // 日期范围
      dateRange: [],
      // 状态数据字典
      statusOptions: [],
      // 数据范围选项
    
      // 菜单列表
      menuOptions: [],
      // 部门列表
      deptOptions: [],
      // 查询参数
      queryParams: {
        status:null,
        pageIndex: 1,
        pageSize: 10,
        username: null 
      },
      queryParam: {
        pageNum: 1,    
        pageSize: 10 
      },
      questionTypelist:[
          { key: 0, value: '待审核'},
          {key: 2, value: '注册成功'},
          {key: 1, value: '注册失败'}
      ],
      // 表单参数
      form: {},
      defaultProps: {
        children: "children",
        label: "label"
      },
      // 表单校验
      rules: {
        roleName: [
          { required: true, message: "角色名称不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    questionTypeFormatter : function(row, column) {
				return row.status == 0 ? "待审核" : row.status == 1 ? "注册失败" : row.status == 2 ? "注册成功": "暂无";
      },
    /** 查询角色列表 */
    getList() {
      this.loading = true;
      getpage(this.queryParams).then(
        response => {
          console.log(response.data)
          this.roleList = response.data;
          this.loading = false;
        }
      );
    },
    // 角色状态修改
    handleStatusChange(row) {
      console.log(row.status)
      let text = row.status === 1? "停用" : "启用";
      console.log(text)
      this.$confirm('确认要"' + text + '""' + row.userName + '"用户吗?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return changeStatus(row.id);
        }).then(() => {
          this.msgSuccess(text + "成功");
        }).catch(function() {
          row.status = row.status === 0 ? 1 : 0;
        }); 
    },
    //数据转换
			formatSex: function(row, column) {
				return row.sex == 1 ? "男" : row.sex == 2 ? "女" : "暂无";
			},
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
   
    /** 删除按钮操作 */
    handleDelete(row) {   
      //console.log(row.id)
      delUser(row.id).then(re => {
        if (re.code === 1) {
         this.getList();
          this.$message.success(re.message)
        } else {
          this.$message.error(re.message)
        }
      })
    },
    handlePass(row) {  
      this.$confirm('确认要重置"' + row.userName + '"用户密码吗?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return resetPassword(row.id);
        }).then(() => {
          this.msgSuccess("重置成功");
        }).catch(function() {
          this.$message.error("重置失败");
        }); 
      //console.log(row.id)
      // resetPassword(row.id).then(re => {
      //   if (re.code === 1) {
      //    this.getList();
      //     this.$message.success(re.message)
      //   } else {
      //     this.$message.error(re.message)
      //   }
      // })
    }
  }
};
</script>